package com.bbs.dao;

import java.math.BigInteger;
import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import util.BaseDao;

import com.bbs.bean.BbsUserInfo;
@Repository
public class BbsUserInfoDao extends BaseDao<BbsUserInfo> {

	@Override
	public Class getEntityClass() {
		// TODO Auto-generated method stub
		return BbsUserInfo.class;
	}

	public List<BbsUserInfo> findAllByPage(int page){
		return getSession().createQuery("from BbsUserInfo ")
		.setFirstResult(page)
		.setMaxResults(20)
		.list();
	
	}

	public int getCountInfo() {
		List list=getHibernateTemplate().executeFind(new HibernateCallback() {
				@Override
				public Object doInHibernate(Session session) throws HibernateException,
						SQLException {
					return session.createSQLQuery("select count(1) from bbs_user_info").list();
				}
		});
		return ((BigInteger) list.get(0)).intValue();
	}

}
